package com.srwl.mytx.im.handler;

import android.util.Log;

import com.srwl.mytx.Constant;
import com.srwl.mytx.im.core.NettyTcpClient;
import com.srwl.mytx.im.protobuf.MessageProtobuf;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * <p>@ProjectName:     NettyChat</p>
 * <p>@ClassName:       HeartbeatRespHandler.java</p>
 * <p>@PackageName:     com.freddy.im</p>
 * <b>
 * <p>@Description:     心跳消息响应处理handler</p>
 * </b>
 * <p>@author:          FreddyChen</p>
 * <p>@date:            2019/04/08 01:08</p>
 * <p>@email:           chenshichao@outlook.com</p>
 */
public class HeartbeatRespHandler extends ChannelInboundHandlerAdapter {
    private static final String TAG = "HeartbeatRespHandler";
    private NettyTcpClient imsClient;

    public HeartbeatRespHandler(NettyTcpClient imsClient) {
        this.imsClient = imsClient;
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        MessageProtobuf.Msg heartbeatRespMsg = (MessageProtobuf.Msg) msg;
        if (heartbeatRespMsg == null || heartbeatRespMsg.getHead() == null) {
            return;
        }


        if (Constant.IM_TYPE_HEAT_BRAT == heartbeatRespMsg.getHead().getMsgType()) {
            Log.d(TAG, "channelRead:收到服务端心跳响应消息 fromId:"+ heartbeatRespMsg.getHead().getFromId());
        } else {
            // 消息透传
            ctx.fireChannelRead(msg);
        }
    }
}
